import request from "../../utils/request";
import type { StoryParams, StoryResponse, NoneResponse, ParentStoryResponse } from "./type";

enum API {
  GRPROJECTSTORY_URL = '/story/{projectId}',
  GUDPROJECTSTARYBYSTORY_URL = '/story/{projectId}/{storyId}',
  GETALLPARENTSTORY_URL = '/story/parentStories/{projectId}',
  GETALLUSERSTORY_URL = '/story/todo',
  CHANGESTORYSTATUS_URL = '/story/changeStatus/{projectId}/{storyId}?status={status}'
}

export const reqGetAllStoryByProjectId = (projectId: number, type: string) => request.get<string, StoryResponse>(API.GRPROJECTSTORY_URL.replace('{projectId}', projectId.toString()), { params: { type } })
export const reqCreateStoryByProjectId = (projectId: number, data: StoryParams) => request.post<StoryParams, NoneResponse>(API.GRPROJECTSTORY_URL.replace('{projectId}', projectId.toString()), data)
export const reqGetProjectStoryBystory = (projectId: number, storyId: number) => request.get<any, StoryResponse>(API.GUDPROJECTSTARYBYSTORY_URL.replace('{projectId}', projectId.toString()).replace('{storyId}', storyId.toString()))
export const reqUpdateProjectStoryBystory = (projectId: number, storyId: number, data: StoryParams) => request.put<StoryParams, NoneResponse>(API.GUDPROJECTSTARYBYSTORY_URL.replace('{projectId}', projectId.toString()).replace('{storyId}', storyId.toString()), data)
export const reqDeleteProjectStoryBystory = (projectId: number, storyId: number) => request.delete<any, NoneResponse>(API.GUDPROJECTSTARYBYSTORY_URL.replace('{projectId}', projectId.toString()).replace('{storyId}', storyId.toString()))
export const reqGetAllParentStoryByProjectId = (projectId: number, type: string) => request.get<string, ParentStoryResponse>(API.GETALLPARENTSTORY_URL.replace('{projectId}', projectId.toString()), { params: { type } })
export const reqGetAllUserStory = (type: string) => request.get<string, StoryResponse>(API.GETALLUSERSTORY_URL, { params: { type } })
export const reqChangeStoryStatus = (projectId: number, storyId: number, status: string) => request.put<string, NoneResponse>(API.CHANGESTORYSTATUS_URL.replace('{projectId}', projectId.toString()).replace('{storyId}', storyId.toString()).replace('{status}', status))